<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <title>设备详情查看</title>
    <link th:href="@{/layui/css/layui.css}" rel="stylesheet"/>
    <script th:src="@{/layui/layui.js}"></script>
    <script th:src="@{/jquery-3.3.1/jquery-3.3.1.js}"></script>
</head>

<body>
<form class="layui-form"  th:action="@{/add}" th:object="${terminfo}" id="terminfoFrom"  method="post">

    <div class="layui-form-item" style="margin-top: 20px;">
        <label class="layui-form-label">imei：</label>
        <div class="layui-input-block">
            <input type="text" name="term_imei" id="term_imei"  style="width: 400px;"   placeholder="请输入imei"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">厂商：</label>
        <div class="layui-input-block">
            <input type="text" name="term_provider" id="term_provider"  style="width: 400px;"  placeholder="请输入厂商"  class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn"  th:onclick="'javascript:save()'">确认</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

</body>

<script>

    function save(){
        var term_imei = $("#term_imei").val();
        var term_provider = $("#term_provider").val();

        if(term_imei.trim()==""){
            parent.layer.msg("请输入imei");
            return;
        }
        if(term_provider.trim()==""){
            parent.layer.msg("请输入厂商");
            return;
        }
        if(isNaN(term_provider)){
            parent.layer.msg("厂商必须是数字，1代表喜讯，2代表前海，3代表明达");
            return;
        }
        $.ajax({
            url: "/terminfoAdd",
            type: "POST",
            data:{"term_imei":term_imei,"term_provider":term_provider},
            dataType: "json",
            success: function(data){
                if(data==1){
                    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);  // 关闭layer
                    parent.layer.msg("新增成功", {icon: 6});
                    parent.location.reload();
                }else{
                    parent.layer.msg("新增失败", {icon: 5});
                }
            }
        });
    }

</script>
</html>